<template>
	<view class="address_box">
		<form @submit="formSubmit" report-submit='true'>
			<view class='addAddress'>
				<view class='list'>
					<view :class="!isPass?'active':''"
						class='item acea-row row-between-wrapper border_bottom1 pos_realtive real_name'>
						 <!--收货人真实姓名-->
						<input @input="getValue" data-type='name' type='text' :placeholder='$t("order.consigneeRealName")' name='realName'
							:value="orderAddress.realName" placeholder-class='placeholder' maxlength="300"></input>
						<view v-if="!isPass" class="tips pos_absolute1">{{$t("order.consigneeNameCannotEmpty")}}</view> <!--收货人姓名不能为空-->
					</view>
					<view class='item acea-row row-between-wrapper border_bottom1'>
						<picker class="area_code new_color400" @change="bindPickerChange" range-key="name"
							:value="phoneIndex" :range="phoneCode">
							<text>{{phoneCode[phoneIndex].code}}</text>
						</picker>
						<input @input="getValue" maxlength="20" data-type='phone' type='number' class="phone"
							:placeholder='$t("order.phoneNumber")' name="phone" :value='orderAddress.userPhone'
							placeholder-class='placeholder'></input><!--手机号码-->
					</view>
					<view class='item acea-row row-between-wrapper border_bottom1' @click="showPicker = true">
						<view class='name' v-if="province == ''">{{$t("order.yourArea")}}</view> <!--所在地区-->
						<view class="address">
							<view class="picker">{{province}} {{city}} {{area}}</view>
						</view>
						<text class="iconfont iconarrow-right1"></text>
					</view>
					<view class='item acea-row row-between-wrapper border_bottom1 detail_address'>
						<textarea @input="getValue" data-type='detail' class="detail_address_input" type='text'
							:placeholder='$t("order.addressTips")' name='detail' placeholder-class='placeholder'
							:value='orderAddress.detail' maxlength="256" /> <!--详细地址，不少于5个字-->
					</view>
					<view class='item acea-row row-between-wrapper border_bottom1'>
						<input maxlength="20" type='text' @input="getValue" data-type='idCard'
							:placeholder='$t("order.IDCardTips1")' name="idCard" :value='orderAddress.idCard'
							placeholder-class='placeholder'></input> <!--身份证号(选填) 输入收货人真实身份号，便于清关-->
					</view>
				</view>
				<view class="idCardTip">{{$t("order.IDCardTips2")}}。</view><!--注：收货人姓名必须要和身份证信息保持是同一人的真实信息-->
				<button class='keepBnt btn_style' form-type="submit">{{$t("publicLang.save")}}</button>
			</view>
		</form>

		<!--============= 所在地区=========== -->
		<view class="address_mask back_mask" @click="showPicker = false" v-if="showPicker">
			<view class="picker_address_box pos_absolute1" @click.stop>
				<view class="picker_btn flex3">
					<view class="btn_cancle" @click="showPicker = false">{{$t("publicLang.cancel")}}</view>
					<view class="btn_confirm" @click="confirmTap">{{$t("publicLang.sure")}}</view>
				</view>
				<view class="picker_box">
					<view class="hk_mac">
						<block v-if="appletType==1">
							<block v-if="orderAddress.areaType==1">
								<picker-view v-if="orderAddress.areaType==1 && district.length > 0" class="picker_view"
									@change="bindChange2" :value="value2">
									<picker-view-column class="area_type">
										<view class="item flex1" v-for="(item,index) in district" :key="index">{{item.name}}
										</view>
									</picker-view-column>
									<picker-view-column class="area_city">
										<view class="item flex1" v-for="(item,index) in district[cityIndex1]['child']"
											:key="index">{{item.name}}</view>
									</picker-view-column>
									<picker-view-column class="area_city">
										<view class="item flex1"
											v-for="(item,index) in district[cityIndex1]['child'][areaIndex1]['child']"
											:key="index">{{item.name}}</view>
									</picker-view-column>
								</picker-view>
							</block>
							<block v-else>
								<picker-view v-if="allArea.length > 0" class="picker_view"
									@change="bindChange2" :value="value2">
									<picker-view-column class="area_type">
										<view class="item flex1" v-for="(item,index) in allArea" :key="index">{{item.name}}
										</view>
									</picker-view-column>
									<picker-view-column class="area_city">
										<view class="item flex1" v-for="(item,index) in allArea[cityIndex1]['child']"
											:key="index">{{item.name}}</view>
									</picker-view-column>
									<picker-view-column class="area_city">
										<view class="item flex1"
											v-for="(item,index) in allArea[cityIndex1]['child'][areaIndex1]['child']"
											:key="index">{{item.name}}</view>
									</picker-view-column>
								</picker-view>
							</block>
						</block>
						<block v-else>
							<picker-view v-if="orderAddress.areaType==2" class="picker_view" @change="bindChange1"
								:value="value1">
								<picker-view-column class="area_type">
									<view class="item flex1" v-for="(item,index) in hkMac" :key="index">{{item.city}}</view>
								</picker-view-column>
								<picker-view-column class="area_city">
									<view class="item flex2" v-for="(item,index) in hkMacArea[areaIndex]" :key="index">
										{{item.name}}
									</view>
								</picker-view-column>
							</picker-view>
							<picker-view v-if="orderAddress.areaType==1 && district.length > 0" class="picker_view"
								@change="bindChange2" :value="value2">
								<picker-view-column class="area_type">
									<view class="item flex1" v-for="(item,index) in district" :key="index">{{item.name}}
									</view>
								</picker-view-column>
								<picker-view-column class="area_city">
									<view class="item flex1" v-for="(item,index) in district[cityIndex1]['child']"
										:key="index">{{item.name}}</view>
								</picker-view-column>
								<picker-view-column class="area_city">
									<view class="item flex1"
										v-for="(item,index) in district[cityIndex1]['child'][areaIndex1]['child']"
										:key="index">{{item.name}}</view>
								</picker-view-column>
							</picker-view>
							<picker-view v-if="orderAddress.areaType==3 && district.length > 0" class="picker_view"
								@change="bindChange2" :value="value2">
								<picker-view-column>
									<view class="item flex1">{{$t("order.overseas")}}</view>
								</picker-view-column>
							</picker-view>
						</block>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		editAddress
	} from '@/api/user.js';
	import {
		getCity
	} from '@/api/api.js';
	import {
		mapGetters
	} from "vuex";

	export default {
		data() {
			return {
				regionDval: ['浙江省', '杭州市', '滨江区'],
				id: 0, //地址id
				userAddress: {
					isDefault: false,
					realName: '',
					phone: ''
				}, //地址详情
				addressInfo: {
					name: '',
					phone: '',
					idCard: '',
					province: '',
					detail: ''
				},
				region: ['', '', ''],
				valueRegion: [0, 0, 0],

				district: [],
				allArea:[],
				multiArray: [],
				multiIndex: [0, 0, 0],
				cityId: 0,
				defaultRegion: ['广东省', '广州市', '番禺区'],
				defaultRegionCode: '440113',
				isPass: true,
				tabList: [{
						name: '港澳地区'
					},
					{
						name: '中国'
					},
					{
						name: '其他国家'
					}
				],
				tabIndex: 0,
				hkMac: [{
						city: '中国香港',
						name: '香港',
						cityId: '714368'
					},
					{
						city: '中国澳门',
						name: '澳门',
						cityId: '714390'
					}
				],
				hkMacArea: [
					[],
					[]
				],
				value1: [0, 0],
				areaIndex: 0,
				province: '',
				city: '',
				area: '',
				value2: [0, 0, 0],
				provinceIndex: 0,
				cityIndex1: 0,
				areaIndex1: 0,
				showAddress: false,
				areaType: 2, //1 大陆  2 港澳 3海外,
				userRegion: '大陆',
				showPicker: false,
				orderAddress: {},

				phoneCode:[{"id":0,"name":"中国","code":"+86"},{"id":1,"name":"香港","code":"+852"},{"id":2,"name":"台湾","code":"+886"},{"id":3,"name":"澳门","code":"+853"},{"id":4,"name":"韩国","code":"+82"},{"id":5,"name":"日本","code":"+81"},{"id":6,"name":"美国","code":"+1"},{"id":7,"name":"英国","code":"+44"},{"id":8,"name":"德国","code":"+49"},{"id":9,"name":"加拿大","code":"+1"},{"id":10,"name":"新加坡","code":"+65"},{"id":11,"name":"印度","code":"+91"},{"id":12,"name":"阿富汗","code":"+93"},{"id":13,"name":"奥兰群岛","code":"+358"},{"id":14,"name":"阿尔巴尼亚","code":"+355"},{"id":15,"name":"阿尔及利亚","code":"+213"},{"id":16,"name":"美属萨摩亚","code":"+1"},{"id":17,"name":"安道尔","code":"+376"},{"id":18,"name":"安哥拉","code":"+244"},{"id":19,"name":"安圭拉","code":"+1"},{"id":20,"name":"安提瓜和巴布达","code":"+1"},{"id":21,"name":"阿根廷","code":"+54"},{"id":22,"name":"亚美尼亚","code":"+374"},{"id":23,"name":"阿鲁巴","code":"+297"},{"id":24,"name":"阿森松岛","code":"+247"},{"id":25,"name":"澳大利亚","code":"+61"},{"id":26,"name":"奥地利","code":"+43"},{"id":27,"name":"阿塞拜疆","code":"+994"},{"id":28,"name":"巴哈马","code":"+1"},{"id":29,"name":"巴林","code":"+973"},{"id":30,"name":"孟加拉国","code":"+880"},{"id":31,"name":"巴巴多斯","code":"+1"},{"id":32,"name":"白俄罗斯","code":"+375"},{"id":33,"name":"比利时","code":"+32"},{"id":34,"name":"伯利兹","code":"+501"},{"id":35,"name":"贝宁","code":"+229"},{"id":36,"name":"百慕大","code":"+1"},{"id":37,"name":"不丹","code":"+975"},{"id":38,"name":"玻利维亚","code":"+591"},{"id":39,"name":"波黑","code":"+387"},{"id":40,"name":"博茨瓦纳","code":"+267"},{"id":41,"name":"巴西","code":"+55"},{"id":42,"name":"英属印度洋领地","code":"+1"},{"id":43,"name":"文莱","code":"+673"},{"id":44,"name":"保加利亚","code":"+359"},{"id":45,"name":"布基纳法索","code":"+226"},{"id":46,"name":"布隆迪","code":"+257"},{"id":47,"name":"柬埔寨","code":"+855"},{"id":48,"name":"喀麦隆","code":"+237"},{"id":49,"name":"佛得角","code":"+238"},{"id":50,"name":"开曼群岛","code":"+1"},{"id":51,"name":"中非共和国","code":"+236"},{"id":52,"name":"乍得","code":"+235"},{"id":53,"name":"智利","code":"+56"},{"id":54,"name":"圣诞岛","code":"+61"},{"id":55,"name":"科科斯（基林）群岛","code":"+61"},{"id":56,"name":"哥伦比亚","code":"+57"},{"id":57,"name":"科摩罗","code":"+269"},{"id":58,"name":"刚果（布）","code":"+242"},{"id":59,"name":"刚果（金）","code":"+243"},{"id":60,"name":"库克群岛","code":"+682"},{"id":61,"name":"哥斯达黎加","code":"+506"},{"id":62,"name":"科特迪瓦","code":"+225"},{"id":63,"name":"克罗地亚","code":"+385"},{"id":64,"name":"古巴","code":"+53"},{"id":65,"name":"塞浦路斯","code":"+357"},{"id":66,"name":"捷克共和国","code":"+420"},{"id":67,"name":"丹麦","code":"+45"},{"id":68,"name":"吉布提","code":"+253"},{"id":69,"name":"多米尼加","code":"+1"},{"id":70,"name":"多米尼加共和国","code":"+1"},{"id":71,"name":"厄瓜多尔","code":"+593"},{"id":72,"name":"埃及","code":"+20"},{"id":73,"name":"萨尔瓦多","code":"+503"},{"id":74,"name":"赤道几内亚","code":"+240"},{"id":75,"name":"厄立特里亚","code":"+291"},{"id":76,"name":"爱沙尼亚","code":"+372"},{"id":77,"name":"埃塞俄比亚","code":"+251"},{"id":78,"name":"福克兰群岛（马尔维纳斯）","code":"+500"},{"id":79,"name":"法罗群岛","code":"+298"},{"id":80,"name":"斐济","code":"+679"},{"id":81,"name":"芬兰","code":"+358"},{"id":82,"name":"法国","code":"+33"},{"id":83,"name":"法属美特罗波利坦","code":"+33"},{"id":84,"name":"法属圭亚那","code":"+594"},{"id":85,"name":"法属波利尼西亚","code":"+689"},{"id":86,"name":"加蓬","code":"+241"},{"id":87,"name":"冈比亚","code":"+220"},{"id":88,"name":"格鲁吉亚","code":"+995"},{"id":89,"name":"加纳","code":"+233"},{"id":90,"name":"直布罗陀","code":"+350"},{"id":91,"name":"希腊","code":"+30"},{"id":92,"name":"格陵兰","code":"+299"},{"id":93,"name":"格林纳达","code":"+1"},{"id":94,"name":"瓜德罗普岛","code":"+590"},{"id":95,"name":"关岛","code":"+1"},{"id":96,"name":"危地马拉","code":"+502"},{"id":97,"name":"几内亚","code":"+224"},{"id":98,"name":"几内亚比绍","code":"+245"},{"id":99,"name":"圭亚那","code":"+592"},{"id":100,"name":"海地","code":"+509"},{"id":101,"name":"洪都拉斯","code":"+504"},{"id":102,"name":"匈牙利","code":"+36"},{"id":103,"name":"冰岛","code":"+354"},{"id":104,"name":"印度尼西亚","code":"+62"},{"id":105,"name":"伊朗","code":"+98"},{"id":106,"name":"伊拉克","code":"+964"},{"id":107,"name":"爱尔兰","code":"+353"},{"id":108,"name":"以色列","code":"+972"},{"id":109,"name":"意大利","code":"+39"},{"id":110,"name":"牙买加","code":"+1"},{"id":111,"name":"约旦","code":"+962"},{"id":112,"name":"哈萨克斯坦","code":"+7"},{"id":113,"name":"肯尼亚","code":"+254"},{"id":114,"name":"基里巴斯","code":"+686"},{"id":115,"name":"科威特","code":"+965"},{"id":116,"name":"吉尔吉斯斯坦","code":"+996"},{"id":117,"name":"老挝人民民主共和国","code":"+856"},{"id":118,"name":"拉脱维亚","code":"+371"},{"id":119,"name":"黎巴嫩","code":"+961"},{"id":120,"name":"莱索托","code":"+266"},{"id":121,"name":"利比里亚","code":"+231"},{"id":122,"name":"利比亚","code":"+218"},{"id":123,"name":"列支敦士登","code":"+423"},{"id":124,"name":"立陶宛","code":"+370"},{"id":125,"name":"卢森堡","code":"+352"},{"id":126,"name":"马其顿共和国","code":"+389"},{"id":127,"name":"马达加斯加","code":"+261"},{"id":128,"name":"马拉维","code":"+265"},{"id":129,"name":"马来西亚","code":"+60"},{"id":130,"name":"马尔代夫","code":"+960"},{"id":131,"name":"马里","code":"+223"},{"id":132,"name":"马耳他","code":"+356"},{"id":133,"name":"马绍尔群岛","code":"+692"},{"id":134,"name":"马提尼克","code":"+596"},{"id":135,"name":"毛里塔尼亚","code":"+222"},{"id":136,"name":"毛里求斯","code":"+230"},{"id":137,"name":"马约特","code":"+269"},{"id":138,"name":"墨西哥","code":"+52"},{"id":139,"name":"密克罗尼西亚","code":"+691"},{"id":140,"name":"摩尔多瓦","code":"+373"},{"id":141,"name":"摩纳哥","code":"+377"},{"id":142,"name":"蒙古","code":"+976"},{"id":143,"name":"黑山","code":"+382"},{"id":144,"name":"蒙特塞拉特","code":"+1"},{"id":145,"name":"摩洛哥","code":"+212"},{"id":146,"name":"莫桑比克","code":"+258"},{"id":147,"name":"缅甸","code":"+95"},{"id":148,"name":"纳米比亚","code":"+264"},{"id":149,"name":"瑙鲁","code":"+674"},{"id":150,"name":"尼泊尔","code":"+977"},{"id":151,"name":"荷兰","code":"+31"},{"id":152,"name":"荷属安的列斯","code":"+599"},{"id":153,"name":"新喀里多尼亚","code":"+687"},{"id":154,"name":"新西兰","code":"+64"},{"id":155,"name":"尼加拉瓜","code":"+505"},{"id":156,"name":"尼日尔","code":"+227"},{"id":157,"name":"尼日利亚","code":"+234"},{"id":158,"name":"纽埃","code":"+683"},{"id":159,"name":"诺福克岛","code":"+672"},{"id":160,"name":"北朝鲜","code":"+850"},{"id":161,"name":"北马里亚纳群岛","code":"+1"},{"id":162,"name":"挪威","code":"+47"},{"id":163,"name":"阿曼","code":"+968"},{"id":164,"name":"巴基斯坦","code":"+92"},{"id":165,"name":"帕劳","code":"+680"},{"id":166,"name":"巴勒斯坦","code":"+970"},{"id":167,"name":"巴拿马","code":"+507"},{"id":168,"name":"巴布亚新几内亚","code":"+675"},{"id":169,"name":"巴拉圭","code":"+595"},{"id":170,"name":"秘鲁","code":"+51"},{"id":171,"name":"菲律宾","code":"+63"},{"id":172,"name":"皮特凯恩","code":"+872"},{"id":173,"name":"波兰","code":"+48"},{"id":174,"name":"葡萄牙","code":"+351"},{"id":175,"name":"波多黎各","code":"+1"},{"id":176,"name":"卡塔尔","code":"+974"},{"id":177,"name":"留尼汪岛","code":"+262"},{"id":178,"name":"罗马尼亚","code":"+40"},{"id":179,"name":"俄罗斯","code":"+7"},{"id":180,"name":"卢旺达","code":"+250"},{"id":181,"name":"圣基茨和尼维斯","code":"+1"},{"id":182,"name":"圣卢西亚","code":"+1"},{"id":183,"name":"圣文森特和格林纳丁斯","code":"+1"},{"id":184,"name":"萨摩亚","code":"+685"},{"id":185,"name":"圣马力诺","code":"+378"},{"id":186,"name":"圣多美和普林西","code":"+239"},{"id":187,"name":"沙特阿拉伯","code":"+966"},{"id":188,"name":"塞内加尔","code":"+221"},{"id":189,"name":"塞尔维亚","code":"+381"},{"id":190,"name":"塞舌尔","code":"+248"},{"id":191,"name":"塞拉利昂","code":"+232"},{"id":192,"name":"斯洛伐克","code":"+421"},{"id":193,"name":"斯洛文尼亚","code":"+386"},{"id":194,"name":"所罗门群岛","code":"+677"},{"id":195,"name":"索马里","code":"+252"},{"id":196,"name":"南非","code":"+27"},{"id":197,"name":"西班牙","code":"+34"},{"id":198,"name":"斯里兰卡","code":"+94"},{"id":199,"name":"圣赫勒拿","code":"+290"},{"id":200,"name":"圣基茨和尼维斯联邦","code":"+1"},{"id":201,"name":"圣卢西亚","code":"+1"},{"id":202,"name":"圣皮埃尔和密克隆岛","code":"+508"},{"id":203,"name":"圣文森特和格林纳丁斯","code":"+1"},{"id":204,"name":"苏丹","code":"+249"},{"id":205,"name":"苏里南","code":"+597"},{"id":206,"name":"斯威士兰","code":"+268"},{"id":207,"name":"瑞典","code":"+46"},{"id":208,"name":"瑞士","code":"+41"},{"id":209,"name":"阿拉伯叙利亚共和国","code":"+963"},{"id":210,"name":"塔吉克斯坦","code":"+992"},{"id":211,"name":"坦桑尼亚","code":"+255"},{"id":212,"name":"泰国","code":"+66"},{"id":213,"name":"东帝汶","code":"+670"},{"id":214,"name":"多哥","code":"+228"},{"id":215,"name":"托克劳","code":"+690"},{"id":216,"name":"汤加","code":"+676"},{"id":217,"name":"特里尼达和多巴哥","code":"+1"},{"id":218,"name":"突尼斯","code":"+216"},{"id":219,"name":"土耳其","code":"+90"},{"id":220,"name":"土库曼斯坦","code":"+993"},{"id":221,"name":"特克斯和凯科斯群岛","code":"+1"},{"id":222,"name":"图瓦卢","code":"+688"},{"id":223,"name":"乌干达","code":"+256"},{"id":224,"name":"乌克兰","code":"+380"},{"id":225,"name":"阿拉伯联合酋长国","code":"+971"},{"id":226,"name":"乌拉圭","code":"+598"},{"id":227,"name":"乌兹别克斯坦","code":"+998"},{"id":228,"name":"瓦努阿图","code":"+678"},{"id":229,"name":"梵蒂冈城国","code":"+39"},{"id":230,"name":"委内瑞拉","code":"+58"},{"id":231,"name":"越南","code":"+84"},{"id":232,"name":"维尔京群岛（英属）","code":"+1"},{"id":233,"name":"维尔京群岛（美属）","code":"+1"},{"id":234,"name":"瓦利斯群岛和富图纳群岛","code":"+681"},{"id":235,"name":"西撒哈拉","code":"+685"},{"id":236,"name":"也门","code":"+967"},{"id":237,"name":"赞比亚","code":"+260"},{"id":238,"name":"桑给巴尔","code":"+255"},{"id":239,"name":"津巴布韦","code":"+263"},{"id":240,"name":"南苏丹","code":"+211"}],
				

				phoneIndex: 0,
				showTab: true, //false:订单修改地址true:正常
			};
		},
		computed: mapGetters(['isLogin','appletType']),
		onLoad(options) {
			var _this = this
			const eventChannel = this.getOpenerEventChannel();
			eventChannel.on('addressInfo', function(data) {
				_this.orderAddress = data.data
				_this.province = _this.orderAddress.address[0]
				_this.city = _this.orderAddress.address[1]
				_this.area = _this.orderAddress.address[2]
				_this.areaType = data.data.areaType
			})
			this.getCityList();
		},
		onShow() {
			uni.setNavigationBarTitle({
				title: this.$t('navigation.changeAddress')
			});
		},
		methods: {
			bindPickerChange: function(e) {
				this.phoneIndex = e.target.value
			},
			getValue(e) {
				let {
					type
				} = e.currentTarget.dataset
				let {
					value
				} = e.detail
				if (type == 'name') {
					this.orderAddress.realName = value
				} else if (type == 'phone') {
					this.orderAddress.userPhone = value
				} else if (type == 'idCard') {
					this.orderAddress.idCard = value
				} else {
					this.orderAddress.detail = value
				}
				let {
					addressInfo
				} = this.$data

				if (addressInfo.name != '' && addressInfo.phone != '' && addressInfo.idCard != '' &&
					addressInfo.province != '' && addressInfo.detail != '') this.isCheck = true
				else this.isCheck = false
			},
			bindChange1(e) {
				let {
					value
				} = e.detail
				let areaType = e.detail.value[0]
				if (value[0] != this.value1[0]) {
					this.value1 = []
					this.value1.push(value[0])
					this.value1.push(0)
				} else {
					this.value1 = []
					this.value1.push(value[0])
					this.value1.push(value[1])
				}
				this.areaIndex = areaType
				console.info(this.value1)
			},
			bindChange2(e) {
				let {
					value
				} = e.detail
				// 省级变化
				if (value[0] != this.value2[0]) {
					this.value2 = []
					this.value2.push(value[0])
					this.value2.push(0)
					this.value2.push(0)
				}
				if (value[1] != this.value2[1]) {
					this.value2 = []
					this.value2.push(value[0])
					this.value2.push(value[1])
					this.value2.push(0)
				} else {
					if (value[0] == this.value2[0] && value[1] == this.value2[1]) {
						this.value2 = []
						this.value2.push(value[0])
						this.value2.push(value[1])
						this.value2.push(value[2])
					}
				}
				console.info(this.value2)
				this.cityIndex1 = e.detail.value[0]
				this.areaIndex1 = e.detail.value[1]
			},
			confirmTap() {
				// 港澳
				this.showPicker = false
				let {
					hkMac,
					value1,
					value2,
					hkMacArea,
					district,
					allArea
				} = this.$data
				
				if (this.appletType==1){
					this.province = allArea[value2[0]]['name']
					this.cityId = allArea[value2[0]]['cityId']
					this.city = allArea[value2[0]]['child']?allArea[value2[0]]['child'][value2[1]]['name']:''
					this.area = allArea[value2[0]]['child']?allArea[value2[0]]['child'][value2[1]]['child'][value2[2]]['name']:''
					this.orderAddress.areaType = 1
					if (!allArea[value2[0]]['child']){
						this.orderAddress.areaType = 3
					}
					if (allArea[value2[0]].cityId == 714368 || allArea[value2[0]].cityId == 714390){
						this.orderAddress.areaType = 2
					}
				}else{
					if (this.areaType == 2) {
						this.province = hkMac[value1[0]]['name']
						this.city = this.province
						this.area = hkMacArea[value1[0]][value1[1]]['name']
						this.cityId = hkMac[value1[0]]['cityId']
					} else if (this.areaType == 1) { //中国大陆
						this.province = district[value2[0]]['name']
						this.cityId = district[value2[0]]['cityId']
						this.city = district[value2[0]]['child'][value2[1]]['name']
						this.area = district[value2[0]]['child'][value2[1]]['child'][value2[2]]['name']
					} else {
						this.province = '海外'
						this.city = ''
						this.area = ''
						this.cityId = ''
					}
				}
				
			},
			// 回去地址数据
			getCityList: function() {
				let that = this;
				getCity().then(res => {
					that.district = res.data
					that.allArea = res.data
					console.info(that.allArea)
					that.allArea.push({name:that.$t("order.overseas")})
					that.initialize();
					res.data.map((i) => {
						if (i.cityId == 714368) {
							that.hkMacArea[0] = i.child[0].child
						} else if (i.cityId == 714390) {
							that.hkMacArea[1] = i.child[0].child
						}
					})
					if (that.areaType == 1 && that.showTab == false) { //订单修改地址去掉香港，澳门
						that.district = res.data.filter(ele => ele.cityId != 714368 && ele.cityId != 714390)
					}
				})
			},
			initialize: function() {
				let that = this,
					province = [],
					city = [],
					area = [];
				if (that.district.length) {
					let cityChildren = that.district[0].child || [];
					let areaChildren = cityChildren.length ? (cityChildren[0].child || []) : [];
					that.district.forEach((item) => {
						province.push(item.name);
					});
					cityChildren.forEach(function(item) {
						city.push(item.name);
					});
					areaChildren.forEach(function(item) {
						area.push(item.name);
					});
					this.multiArray = [province, city, area]
				}
			},
			/**
			 * 提交用户添加地址
			 * 
			 */
			formSubmit: function(e) {
				let that = this,
					value = e.detail.value;
				if (!value.realName) {
					this.isPass = false
					that.$util.Tips({
						title: that.$t('order.pleaseFillInTheConsigneeName') //请填写收货人姓名
					}); 
					return
				} else {
					this.isPass = true
				}
				if (!value.phone) return that.$util.Tips({
					title: that.$t('order.pleaseFillInTheContactNumber')//请填写联系电话
				});
				if (that.phoneIndex == 0 && !/^1(3|4|5|7|8|9|6)\d{9}$/i.test(value.phone)) return that.$util.Tips({
					title: that.$t('order.pleaseEnterTheCorrectPhoneNumber')//请输入正确的手机号码
				});
				if (that.region == '省-市-区') return that.$util.Tips({
					title: that.$t('order.pleaseSelectYourRegion')//请选择所在地区
				});
				if (!value.detail) return that.$util.Tips({
					title: that.$t('order.pleaseFillInTheDetailedAddress')//请填写详细地址
				});
				if (value.idCard && !this.$u.test.idCard(value.idCard)) return that.$util.Tips({
					title: that.$t('order.IDCardFormatIsIncorrect')//身份证格式不正确
				});
				var phoneOLD = value.phone
				value.phone = that.phoneCode[that.phoneIndex].id + "|" + that.phoneCode[that.phoneIndex].code + ' ' +
					phoneOLD
				const data = {
					areaType: this.orderAddress.areaType,
					city: this.city,
					detail: this.orderAddress.detail,
					district: this.area,
					province: this.province,
					id: this.orderAddress.id,
					idCard: this.orderAddress.idCard == "" || this.orderAddress.idCard == null ?null :
						this.orderAddress.idCard,
					realName: this.orderAddress.realName,
					userPhone: this.orderAddress.userPhone == "" ? null : this.orderAddress.userPhone,
				};
				uni.showLoading({
					title: that.$t('publicLang.pleaseWait'),
					mask: true
				})
				editAddress(data).then(res => {
					that.$util.Tips({
						title: that.$t('publicLang.successfulOperation'),
						icon: 'success'
					});
					uni.navigateBack()
					const eventChannel = that.getOpenerEventChannel();
					eventChannel.emit('acceptDataFromOpenedPage', {
						data: 'test'
					});
				}).catch(err => {
					value.phone = phoneOLD
					return that.$util.Tips({
						title: err
					});
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.flex1 {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.flex2 {
		display: flex;
		align-items: center;
	}

	.flex3 {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.idCardTip {
		color: #BCBCBC;
		font-size: 24rpx;
		text-align: center;
	}

	.border_bottom1 {
		border-bottom: 1rpx solid #e6e6e6;
	}

	.pos_absolute {
		position: absolute;
		top: 0;
		left: 0;
		bottom: 0;
		right: 0;
	}

	.pos_absolute1 {
		position: absolute;
	}

	.pos_realtive {
		position: relative;
	}

	.back_mask {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		top: 0;
		background-color: rgba(0, 0, 0, 0.5);
	}

	// 新增样式start===============
	input {
		color: rgba(34, 34, 34, 1) !important;
	}

	.picker_address_box {
		left: 0;
		right: 0;
		height: 700rpx;
		background-color: #FFFFFF;
		bottom: 0;
		padding: 0 20rpx;

		.picker_btn {
			padding: 20rpx 0;
			font-size: 28rpx;
			color: #222222;

			.btn_confirm {
				background-color: rgba(34, 34, 34, 1);
				border-radius: 4rpx;
				color: #FFFFFF;
				padding: 10rpx 20rpx;
			}
		}

		.switch_address {
			padding: 0 10rpx;
			margin-top: 20rpx;

			.line {
				left: 0;
				right: 0;
				height: 4rpx;
				background-color: rgba(34, 34, 34, 1) !important;
				bottom: -10rpx;
			}
		}

		.picker_box {
			height: 320rpx;
			position: absolute;
			width: 100%;
			bottom: 200rpx;

			.picker_view {
				height: 320rpx;
				font-size: 32rpx;
			}

			.area_type {
				width: 300rpx;
				flex: initial;
			}

			.area_city {
				width: 300rpx;
				flex: initial;
			}
		}
	}

	.address_box {
		position: fixed;
		top: 0rpx;
		left: 0;
		bottom: 0;
		right: 0;
		background-color: #FFFFFF;
	}

	.area_code {
		padding-right: 24rpx;
		border-right: 1rpx solid rgba(204, 204, 204, 1);
	}

	.phone {
		flex: 1;
		margin-left: 24rpx;
	}

	.detail_address {
		padding: 0 !important;
	}

	.detail_address_input {
		padding-top: 25rpx;
		height: 150rpx;
	}

	.iconarrow-right1 {
		font-size: 28rpx !important;
	}

	.import_wx {
		width: 690rpx;
		height: 110rpx;
		color: #DE7E8D;
		font-size: 28rpx;
		border-top: 1rpx solid rgba(230, 230, 230, 1);
		border-bottom: 1rpx solid rgba(230, 230, 230, 1);
		margin: 56rpx auto;
	}

	.import_wx1 {
		color: #AF8A40;
	}

	.tips {
		font-size: 22rpx;
		color: rgba(210, 80, 100, 1);
		bottom: -34rpx;
	}

	.active {
		border-color: rgba(210, 80, 100, 1);
	}

	// 新增样式end===================
	// 
	.addAddress .list {
		background-color: #fff;
		padding: 0 30rpx;
		border-top: 1px solid rgba(227, 229, 233, 1);
	}

	.addAddress .list .item {
		padding: 30rpx 0;
		// border-top: 1rpx solid #eee;
	}

	.addAddress .list .item .name {
		width: 195rpx;
		font-size: 28rpx;
		color: rgba(187, 187, 187, 1);
	}

	.addAddress .list .item .address {
		// width: 412rpx;
		flex: 1;
		margin-left: 20rpx;
	}

	.addAddress .list .item input {
		width: 475rpx;
		font-size: 28rpx;
		color: rgba(187, 187, 187, 1);
	}

	.addAddress .list .item .placeholder {
		color: #ccc;
	}

	.addAddress .list .item picker .picker {
		width: 410rpx;
		font-size: 30rpx;
	}

	.addAddress .list .item picker .iconfont {
		font-size: 43rpx;
	}

	.addAddress .default {
		padding: 0 30rpx;
		height: 90rpx;
		background-color: #fff;
		margin-top: 23rpx;
	}

	.addAddress .default checkbox {
		margin-right: 15rpx;
	}

	.addAddress .keepBnt {
		width: 690rpx !important;
		height: 86rpx;
		border-radius: 50rpx;
		text-align: center;
		line-height: 86rpx;
		margin: 50rpx auto;
		font-size: 32rpx;
		color: #fff;
		background-color: #222222 !important;
	}
</style>
